home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok44.lha
/
Scan
/
Scan.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
5KB
|
184 lines
(**********************************************************************
:Program. Scan.mod
:Contents. Scans for a file
:Author. Gerhard 'Fido' Schneider
:Address. Schadewitzstraße 22, D-8700 Würzburg
:Copyright. Buplik Tomain
:Language. Modula-2
:Translator. M2Amiga A+L V3.2d
:Imports. Arp
:History. Unknown
**********************************************************************)
MODULE Scan;
FROM Dos IMPORT FileLockPtr,accessRead,FileInfoBlockPtr,FileInfoBlock,
ctrlC,ctrlF;
FROM SYSTEM IMPORT ADR,ADDRESS,CAST,LONGSET;
FROM Str IMPORT Concat,Length,Compare;
FROM Arp IMPORT GADS,ArpAlloc,Puts,Printf,StdAnchorPathPtr,FindFirst,
FindNext,FreeAnchorChain,AnchorPathPtr,stdAnchorSize,
ReadLine,ToUpper,Examine,ExNext,Lock,UnLock,DeleteFile;
FROM Arts IMPORT dosCmdBuf,dosCmdLen;
CONST Template='Files,D=DELETE/s,A=ASK/s,Q=QUIET/s';
Help='Usage: Scan <wildcards> [DELETE] [ASK] [QUIET]';
Help2='(Scanes or deletes files in dirs recursive.)';
TYPE String=ARRAY[0..107] OF CHAR;
StringPtr=POINTER TO String;
ArgType=RECORD
Files:StringPtr;
Delete,Ask,Quiet:ADDRESS;
END;
VAR Flag:BOOLEAN;
Len,i:INTEGER;
lock:FileLockPtr;
Argc:INTEGER;
Slash:CHAR;
Arg:ArgType;
ap:StdAnchorPathPtr;
Path,FileName,Read:String;
PROCEDURE Scan(VAR Dir:String);
VAR lock:FileLockPtr;
infoBlock:FileInfoBlockPtr;
Flag:BOOLEAN;
fName,NewDir:String;
Len:INTEGER;
BEGIN
infoBlock:=ArpAlloc(SIZE(FileInfoBlock));
NewDir:=Dir;
Len:=Length(NewDir);
IF (Len>0) AND (NewDir[Len-1]#':') THEN
Concat(NewDir,'/')
END;
Concat(NewDir,FileName);
IF FindFirst(ADR(NewDir),AnchorPathPtr(ADDRESS(ap)))=0 THEN
REPEAT
IF ap^.anchor.info.dirEntryType<1 THEN
IF Arg.Delete#NIL THEN
IF Arg.Ask#NIL THEN
Len:=Printf(ADR('Delete '),NIL);Len:=Printf(ADR(ap^.buffer),NIL);
Len:=Printf(ADR(' ? '),NIL);Len:=ReadLine(ADR(Read));
Read[0]:=ToUpper(Read[0])
ELSE
Read[0]:='Y'
END;
IF (Arg.Quiet=NIL) AND ((Read[0]='Y') OR (Read[0]='J')) THEN
Len:=Printf(ADR('Deleting '),NIL);Len:=Puts(ADR(ap^.buffer));
Flag:=DeleteFile(ADR(ap^.buffer));
END;
IF NOT Flag THEN
Len:=Puts(ADR('Not deleted - file is protected for deletion'))
END
ELSE
Len:=Printf(ADR('Found '),NIL);Len:=Puts(ADR(ap^.buffer))
END
END
UNTIL FindNext(AnchorPathPtr(ADDRESS(ap)))#0
END;
lock:=Lock(ADR(Dir),accessRead);
Flag:=Examine(lock,infoBlock);
WHILE Flag DO
Flag:=ExNext(lock,infoBlock);
IF Flag THEN
fName:=CAST(String,infoBlock^.fileName);
IF (infoBlock^.dirEntryType >0) THEN
NewDir:=Dir;
Len:=Length(NewDir);
IF (Len#0) AND (NewDir[Len-1]#':') THEN
Concat(NewDir,'/')
END;
Concat(NewDir,fName);
IF Arg.Quiet=NIL THEN
Len:=Printf(ADR(' Scanning '),NIL);Len:=Puts(ADR(NewDir))
END;
Scan(NewDir);
END;
END;
END;
UnLock(lock);
END Scan;
PROCEDURE ExtractPath(VAR Path:String);
VAR i,Len:INTEGER;
BEGIN
Len:=Length(Path);
IF Len=0 THEN
RETURN
END;
i:=Len-1;
LOOP
IF (Path[i]='/') THEN
Path[i]:=0C;EXIT
ELSIF (Path[i]=':') THEN
Path[i+1]:=0C;EXIT
ELSIF i=0 THEN
Path[0]:=0C;EXIT
END;
DEC(i)
END;
END ExtractPath;
PROCEDURE ExtractFileName(VAR FileName:String);
VAR i,j,Len:INTEGER;
Dummy:String;
BEGIN
Len:=Length(FileName);
IF Len=0 THEN
RETURN
END;
i:=Len-1;
LOOP
IF (FileName[i]=':') OR (FileName[i]='/') THEN
FOR j:=i+1 TO Len DO
Dummy[j-i-1]:=FileName[j];
END;
FileName:=Dummy;
EXIT
END;
IF i=0 THEN
EXIT
ELSE
DEC(i)
END;
END;
END ExtractFileName;
BEGIN
Slash:='/';
LOOP
Argc:=GADS(dosCmdBuf,dosCmdLen,ADR(Help),ADR(Arg),ADR(Template));
IF Argc<1 THEN
Len:=Puts(ADR(Help));
Len:=Puts(ADR(Help2));EXIT
END;
ap:=ArpAlloc(SIZE(ap^));
IF ap=NIL THEN
Len:=Puts(ADR('How about buying a 2 Meg memory-expansion?'));EXIT
END;
ap^.anchor.length:=stdAnchorSize;
ap^.anchor.breakBits:=LONGSET{ctrlC..ctrlF};
Path:=Arg.Files^;
FileName:=Arg.Files^;
ExtractPath(Path);
ExtractFileName(FileName);
lock:=Lock(ADR(Path),NIL);
IF lock=NIL THEN
Len:=Puts(ADR('Bad path'));EXIT
END;
IF (Arg.Quiet=NIL) AND (Length(FileName)=0) THEN
Len:=Puts(ADR('Bad filename'));EXIT
END;
Scan(Path);
FreeAnchorChain(AnchorPathPtr(ADDRESS(ap)));
EXIT;
END
END Scan.